package cn.kn.common.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author WangJiang
 * @create 2020-11-25 10:10
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
public class R<T>{

    private Integer code;
    private String msg;
    private T data;

    public static R<Void> ok(String msg){ return new R<Void>(RCode.SUCCESS.getCode(),msg,null); }
    public static<T> R<T> ok(String msg,T data){
        return new R<T>(RCode.SUCCESS.getCode(),msg,data);
    }
    public static<T> R<T> ok(T data){
        return new R<T>(RCode.SUCCESS.getCode(),RCode.SUCCESS.getMsg(),data);
    }
    public static R<Void> ok(){ return new R<Void>(RCode.SUCCESS.getCode(),RCode.SUCCESS.getMsg(),null); }
    public static R<Void> error(RCode rCode){ return new R<Void>(rCode.getCode(),rCode.getMsg(),null); }
    public static R<Void> error(){ return R.error(RCode.ERROR); }

}
